package effective_java.universal;

import java.util.Arrays;
import java.util.Comparator;

public class Test {
    public static void main(String[] args) {
        unexpectedResOfDouble();
        unexpectedResOfCompare();
    }

    // 60
    private static void unexpectedResOfDouble() {
        System.out.println(1.01 - 0.41);// res: 0.6000000000000001
    }

    // 61
    private static void unexpectedResOfCompare() {
        // error version
        Comparator<Integer> naturalOrder = (i, j) -> (i < j) ? -1 : (i == j ? 0 : 1);
        System.out.println(naturalOrder.compare(new Integer(42), new Integer(42)));// res: 1

        // fixed version
        Comparator<Integer> fixedNaturalOrder = (iBoxed, jBoxed) -> {
            int i = iBoxed, j = jBoxed;
            return (i < j) ? -1 : (i == j ? 0 : 1);
        };
        System.out.println(fixedNaturalOrder.compare(new Integer(42), new Integer(42)));// res: 0
    }
}

